package com.liuyi.controller.sys;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.liuyi.model.VisitReservation;
import com.liuyi.service.VisitReservationService;
import com.liuyi.util.CommonUtil;
import com.liuyi.util.excle.PoiExcelExport;
import com.liuyi.util.excle.ServletUtil;

/**
 * 
 * @ClassName: VisitReservationController 
 * @Description: TODO
 * @author: 12090
 * @date: 2018年10月23日 上午9:46:46
 */
@RestController
public class VisitReservationController {

	@Autowired
	private VisitReservationService visitReservationService;
	
	@RequestMapping(value = "/exportVisit",method = RequestMethod.GET)
	public void exportVisit(HttpServletRequest req,HttpServletResponse resp){
		//LOG.info("ENTER /uas/admin/export,paramter is {}",json);
        //准备数据
        List<VisitReservation> list = visitReservationService.selectVisitReservationAll();
        
		//执行导出
		String fileName = "预约参访名单.xls";
		ServletUtil su = new ServletUtil(fileName, req, resp);
		su.poiExcelServlet();
		//设置表头
		String[] heads = {"序号","ID","目前所在地","家长姓名","家长手机号","学生姓名","学生生日","申请年级","预约申请","预约时间","创建时间"};
		String[] cols = {"","id","area","parentName","parentPhone","studentName","birthday","gradeApplication","appointmentApplication","appointmentTime","createTime"};
		//这里传第几个字段是数字，从0开始
        int[] numerics = {0,1};
		ServletUtil suresp = new ServletUtil(resp);
		PoiExcelExport<VisitReservation> pee = new PoiExcelExport<>(fileName, heads, cols, list, numerics, suresp.getOut());
		pee.exportExcel();
	}
	
	@GetMapping("/visitReservationlist")
    public JSONObject listUser(HttpServletRequest request) {
        return visitReservationService.selectVisitReservationAll(CommonUtil.request2Json(request));
    }
}
